home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / ViewerOptBtnSample / Source / Events.c next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  4.0 KB  |  200 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*        EVENTS            */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <ToolUtils.h>
  11. #include <Controls.h>
  12. #include <MacWindows.h>
  13.  
  14. #include <QD3D.h>
  15. #include <QD3DViewer.h>
  16.  
  17. #include "myglobals.h"
  18. #include "myevents.h"
  19. #include "mymenus.h"
  20. #include "misc.h"
  21. #include "process.h"
  22.  
  23. extern    WindowPtr                gModelWindow;
  24. extern    TQ3ViewerObject            gViewer;
  25.  
  26. /****************************/
  27. /*    PROTOTYPES            */
  28. /****************************/
  29.  
  30. static void DoHighLevelEvent(void);
  31. static Boolean IsDAWindow(WindowPtr whichWindow);
  32. static OSErr  hasGotRequiredParams(AppleEvent *appEvent);
  33. static void    HandleMouseDown(void);
  34.  
  35.  
  36. /****************************/
  37. /*    CONSTANTS             */
  38. /****************************/
  39.  
  40.  
  41. /**********************/
  42. /*     VARIABLES      */
  43. /**********************/
  44.  
  45. EventRecord    gTheEvent;
  46.  
  47.  
  48. /******************** HANDLE EVENTS ************************/
  49.  
  50. void HandleEvents(void)
  51. {
  52. char    theChar;
  53. GrafPtr    oldPort;
  54.         
  55.     WaitNextEvent(everyEvent,&gTheEvent, 0, 0);
  56.                 
  57.                 /* SEE IF VIEWER HANDLES EVENT */
  58.                 
  59.     if (Q3ViewerEvent(gViewer, &gTheEvent))
  60.         return;
  61.                 
  62.                 
  63.             /* NOPE, LET'S HANDLE IT OURSELVES */
  64.             
  65.     switch (gTheEvent.what)
  66.     {
  67.         case    nullEvent:
  68.                 Q3ViewerAdjustCursor(gViewer, &gTheEvent.where);
  69.                 DoModelWindowNullEvent();
  70.                 break;
  71.                 
  72.         case    mouseDown:
  73.                 HandleMouseDown();
  74.                 break;
  75.                 
  76.         case    keyDown:
  77.         case    autoKey:
  78.                 theChar    = gTheEvent.message & charCodeMask;
  79.                 if    ((gTheEvent.modifiers & cmdKey) != 0)
  80.                     HandleMenuChoice(MenuKey(theChar));
  81.                 break;
  82.                 
  83.         case    updateEvt:
  84.                 if (!IsDAWindow((WindowPtr)gTheEvent.message))
  85.                 {
  86.                     GetPort (&oldPort);
  87.                     SetPort ((WindowPtr)gTheEvent.message);
  88.                     BeginUpdate((WindowPtr)gTheEvent.message);
  89.                     DrawControls((WindowPtr)gTheEvent.message);
  90.                     
  91.                     if ((WindowPtr)gTheEvent.message == gModelWindow)
  92.                     {
  93.                     
  94.                     }
  95.                                             
  96.                     EndUpdate((WindowPtr)gTheEvent.message);
  97.                     SetPort(oldPort); 
  98.                 }
  99.                 else 
  100.                 {
  101.                     BeginUpdate((WindowPtr)gTheEvent.message);
  102.                     EndUpdate((WindowPtr)gTheEvent.message);
  103.                 }
  104.                 break;
  105.                 
  106.         case    kHighLevelEvent:
  107.                 DoHighLevelEvent();
  108.                 break;
  109.     }
  110. }
  111.  
  112.  
  113. /**************** DO HIGH LEVEL EVENT *****************/
  114.  
  115. static void DoHighLevelEvent(void)
  116. {
  117. OSErr    myErr;
  118.  
  119.     myErr = AEProcessAppleEvent(&gTheEvent);
  120. }
  121.  
  122.  
  123. /************** HANDLE MOUSE DOWN *******************/
  124.  
  125. static void HandleMouseDown(void)
  126. {
  127.     WindowPtr        whichWindow;
  128.     short             thePart;
  129.     long            menuChoice, windSize;
  130.     
  131.     thePart    =    FindWindow(gTheEvent.where, &whichWindow);
  132.     switch(thePart)
  133.     {
  134.         case    inMenuBar:
  135.                 menuChoice = MenuSelect(gTheEvent.where);
  136.                 HandleMenuChoice(menuChoice);
  137.                 break;
  138.                 
  139.         case    inSysWindow:
  140.                 SystemClick(&gTheEvent, whichWindow);
  141.                 break;
  142.                 
  143.         case    inDrag:
  144.                 DragWindow(whichWindow,gTheEvent.where, &qd.screenBits.bounds);
  145.                 break;
  146.                 
  147.         case    inGoAway:
  148.                 DisposeWindow (whichWindow);
  149.                 break;
  150.                 
  151.         case    inContent:
  152.                 SelectWindow(whichWindow);
  153.  
  154.                 break;
  155.                 
  156.         case    inGrow:
  157.                 windSize = GrowWindow(whichWindow, gTheEvent.where,
  158.                                     &(**GetGrayRgn()).rgnBBox);
  159.                 if (windSize != 0)
  160.                 {
  161.                     SetPort(whichWindow);
  162.                     EraseRect(&whichWindow->portRect);
  163.                     SizeWindow(whichWindow,LoWord(windSize),
  164.                                 HiWord(windSize), NORMAL_UPDATES);
  165.                     InvalRect(&whichWindow->portRect);
  166.                     
  167.                     if (whichWindow == gModelWindow)            // see if change Skeleton window
  168.                     {
  169. //                        QD3D_ChangeDrawSize(&gModelViewInfo);
  170.                     }
  171.                 } 
  172.                 break;
  173.     }
  174. }
  175.  
  176.  
  177. /**************** IS DA WINDOW ***********************/
  178.  
  179. static Boolean IsDAWindow(WindowPtr whichWindow)
  180. {
  181.     if    (whichWindow == nil)
  182.         return (false);
  183.     else
  184.         return (((WindowPeek)whichWindow)->windowKind < 0);
  185. }
  186.  
  187.  
  188.  
  189.  
  190. /*********************** MY APPLE EVENT: QUIT APPLICATION *************************/
  191.  
  192. pascal OSErr MyAE_QuitApplication(AppleEvent *theAppleEvent, AppleEvent *reply,
  193.                             SInt32 handlerRefcon)
  194. {
  195.     #pragma unused(theAppleEvent, reply, handlerRefcon)
  196.  
  197.     CleanQuit();
  198.     return(noErr);
  199. }
  200.